package com.zxy.supplier_system.server.service

import com.zxy.supplier_system.server.repository.EmployeeRepository
import com.zxy.supplier_system.server.repository.SystemServiceRepository
import com.zxy.supplier_system.server.utils.IntIdAndName
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class SaleManagerService(
    private val systemServiceService: SystemServiceService,
    private val employeeRepository: EmployeeRepository
) {

    @Transactional
    fun getSaleManagers(): List<IntIdAndName> {
        return this.employeeRepository.findAll(
            EmployeeRepository.Specifications.existsSaleManager()
                .and(
                    SystemServiceRepository.Specifications.systemServiceEquals(
                        { root -> root }, systemServiceService.getCurrentSystemService()
                    )
                )
        ).map {
            IntIdAndName(it.id!!, it.name)
        }
    }

}
